<!-- 组件说明 -->
<template>
  <div class="havebottombar purseIndex">
    <div class="container clearfix">
      <div class="top">
        <div @click.stop="headerClickFn" class="userPic">
          <img v-if="userStoreData.avatar" :src="userStoreData.avatar" />
          <img v-else :src="defaultPic" />
        </div>
        <p @click.stop="headerClickFn" class="nickName">
          {{ userStoreData.nickName ? userStoreData.nickName : "----" }}
        </p>
        <img
          v-if="false"
          @click="openKf"
          class="rightTopBtn"
          :src="righttop"
          alt=""
        />
        <img
          v-if="ifLoginFn()"
          @click.stop="gotoEdit"
          class="rightBtnWhite"
          :src="rightBtnWhite"
          alt=""
        />
      </div>
      <div class="center">
        <div class="content">
          <div
            class="li"
            @click.stop="contentFn(item)"
            v-for="(item, index) in contentArrary"
            :key="index"
          >
            <div class="left">
              <img class="leftIcon" :src="item.imgIcon" />
              <p>{{ item.title }}</p>
            </div>
            <img class="rightbtn" :src="rightbtn" />
          </div>
          <div class="email" v-copy="ourEmail">
            <img :src="SentEmail">
            <span>Copy and send email to us!</span>
          </div>
          <div
              v-if="userStoreData.isLogin"
              src="@/assets/imgs/percenter/logout.png"
              class="gotoLogoutBtn2"
              @click.stop="gotoLogout"
          >
              LOGOUT
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { ifLogin, utilGotoLogin } from "@/utils/index.js";
import { mapState } from "vuex";
import { Dialog } from "vant";

export default {
  components: {
    // compSep
  },
  data() {
    return {
      nickName: "Visitor",
      img: require("@/assets/imgs/index/defaultPic.png"),
      righttop: require("@/assets/imgNews/percenter/righttop.png"),
      rightbtn: require("@/assets/imgNews/percenter/rightbtn.png"),
      rightBtnWhite: require("@/assets/imgNews/percenter/rightBtnWhite.png"),
      defaultPic: require("@/assets/imgs/index/defaultPic.png"),
      SentEmail: require("@/assets/imgNews/percenter/icon_email.png"),
      contentArrary: [
        {
          imgIcon: require("@/assets/imgNews/percenter/1.png"),
          title: "Sports Statistics",
          functionType: "goto",
          params: "percenterSports"
        },
        {
          imgIcon: require("@/assets/imgNews/percenter/2.png"),
          title: "Wallet Statistics",
          functionType: "goto",
          params: "percenterWallet"
        },
        {
          imgIcon: require("@/assets/imgNews/percenter/3.png"),
          title: "Rank",
          functionType: "goto",
          params: "rank"
        },
        {
          imgIcon: require("@/assets/imgNews/percenter/4.png"),
          title: "Record",
          functionType: "goto",
          params: "percenterGiftRecord"
        },
        {
          imgIcon: require("@/assets/imgNews/percenter/5.png"),
          title: "Invite",
          functionType: "goto",
          params: "percenterInvite"
        }
      ],

      uploadpicUrl: "", // 上传返给我的头像图片地址
      ourEmail:'jkeya4932@@gmail.com'
    };
  },
  computed: mapState({
    // 箭头函数可使代码更简练
    userStoreData: state => state.user
    // radius() {
    //   return 50 - 6 / 2;
    // }
  }),
  methods: {
    // 复制到剪切板
    copyfn() {
      copy(this.pay_address);
      this.$toast("Copy success");
    },
    openKf() {
      console.log("http://192.168.3.92:8080/");
      // window.StepSDK.jumpUrl("http://192.168.3.92:8080/", "1");//1为app内 非1位app外部浏览器
      window.StepSDK.jumpUrl("http://192.168.3.92:8080/", "333");//1为app内 非1位app外部浏览器
    },
    gotoEdit() {
      this.$router.push({
        name: "percenterEidt"
      });
    },
    ifLoginFn() {
      return ifLogin();
    },
    headerClickFn() {
      if (ifLogin()) {
        console.log("跳转编辑页面");
      } else {
        this.gotoLogin();
      }
    },
    gotoLogin() {
      utilGotoLogin();
    },
    gotoLogout() {
      let zs = this;
      Dialog.confirm({
        title: "Tips",
        message: "Sure Logout？",
        confirmButtonText:'Yes',
        cancelButtonText:'No'
      })
        .then(() => {
          zs.$store.commit("resetuserdata");
          window.sessionStorage.clear();
          window.localStorage.clear();
          zs.goto("login");
        })
        .catch(() => {
          // on cancel
        });
    },
    contentFn(item) {
      if (!ifLogin()) {
        utilGotoLogin();
      } else {
        let { params } = item;
        if (params) {
          this.$router.push({ name: params });
        } else {
          this.$toast("Waiting");
        }
      }
    },
    pageinit() {
      // this.get_inforeward();
      // this.get_inforewardtop10();
    },
    // 奖励信息获取
    get_inforeward() {
      let zs = this;
      this.$toast.loading({
        duration: 0,
        forbidClick: true
      });
      this.api.bussiness.get_inforeward({}).then(res => {
        zs.$toast.clear();
        if (res.data.code === 200) {
          zs.userjhstatus = res.data.data.enable == 1 ? 2 : 1;
          zs.invite_reward_total = res.data.data.invite_reward_total;
          zs.static_reward_total = res.data.data.static_reward_total;
          zs.last_invite_reward = res.data.data.last_invite_reward;
          zs.last_static_reward = res.data.data.last_static_reward;
          zs.my_hashrate = res.data.data.my_hashrate;
          zs.my_hashrate_static = res.data.data.my_hashrate_static;
          zs.my_hashrate_invite = res.data.data.my_hashrate_invite;
          zs.total_hashrate = res.data.data.total_hashrate;
          zs.total_hashrate_static = res.data.data.total_hashrate_static;
          zs.total_hashrate_invite = res.data.data.total_hashrate_invite;
          zs.total_out = res.data.data.total_out;
          zs.total_out_static = res.data.data.total_out_static;
          zs.total_out_invite = res.data.data.total_out_invite;
          zs.gzjg = res.data.data.price;

          // invite_reward_total: '',//核裂变总收益
          // static_reward_total: '',//核聚变总收益
          // last_invite_reward : '',//上轮裂变收益
          // last_status_reward: '',//上轮聚变收益
          // my_hashrate: '',//我的算力
          // total_hashrate: '',//全网算力
          // total_out: '',// 上轮产币
        } else {
          zs.$toast(res.data.info);
        }
      });
    },
    // 奖励top10获取
    get_inforewardtop10() {
      this.$toast.loading({
        duration: 0,
        forbidClick: true
      });
      let zs = this;
      this.api.bussiness.get_inforewardtop10({}).then(res => {
        zs.$toast.clear();
        if (res.data.code === 200) {
          zs.top10list = res.data.data;
        } else {
          zs.$toast(res.data.info);
        }
      });
    },
    // 路有跳转
    goto(name) {
      this.$router.push({
        name
      });
    },
    fnstop() {
      return false;
    }
  },
  mounted() {
    this.pageinit();
    window.setImageUrl = url => {
      alert("图片上传地址 url=" + url);
      this.uploadpicUrl = url;
    };
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {} //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>

<style lang="less" scoped>
@import url("./../../../assets/css/common.less");
@import url("./purseindex.less");
</style>
